/*     */ package com.zimbra.cs.account;
/*     */ 
/*     */ import com.google.common.collect.Lists;
/*     */ import com.google.common.collect.Sets;
/*     */ import com.zimbra.common.account.Key.DataSourceBy;
/*     */ import com.zimbra.common.account.Key.IdentityBy;
/*     */ import com.zimbra.common.account.Key.ServerBy;
/*     */ import com.zimbra.common.account.Key.SignatureBy;
/*     */ import com.zimbra.common.account.Key.UCServiceBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.auth.AuthContext.Protocol;
/*     */ import com.zimbra.cs.account.names.NameUtil.EmailAddress;
/*     */ import com.zimbra.soap.admin.type.DataSourceType;
/*     */ import java.util.Collections;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Account
/*     */   extends ZAttrAccount
/*     */   implements GroupedEntry, AliasedEntry
/*     */ {
/*     */   public Account(String name, String id, Map<String, Object> attrs, Map<String, Object> defaults, Provisioning prov)
/*     */   {
/*  42 */     super(name, id, attrs, defaults, prov);
/*     */   }
/*     */   
/*     */   public Entry.EntryType getEntryType()
/*     */   {
/*  47 */     return Entry.EntryType.ACCOUNT;
/*     */   }
/*     */   
/*     */   public void deleteAccount() throws ServiceException {
/*  51 */     getProvisioning().deleteAccount(getId());
/*     */   }
/*     */   
/*     */   public void rename(String newName) throws ServiceException {
/*  55 */     getProvisioning().renameAccount(getId(), newName);
/*     */   }
/*     */   
/*     */   public void modify(Map<String, Object> attrs) throws ServiceException {
/*  59 */     getProvisioning().modifyAttrs(this, attrs);
/*     */   }
/*     */   
/*     */   public void addAlias(String alias) throws ServiceException {
/*  63 */     getProvisioning().addAlias(this, alias);
/*     */   }
/*     */   
/*     */   public void removeAlias(String alias) throws ServiceException {
/*  67 */     getProvisioning().removeAlias(this, alias);
/*     */   }
/*     */   
/*     */   public void authAccount(String password, AuthContext.Protocol proto) throws ServiceException {
/*  71 */     getProvisioning().authAccount(this, password, proto);
/*     */   }
/*     */   
/*     */   public void changePassword(String currentPassword, String newPassword) throws ServiceException {
/*  75 */     getProvisioning().changePassword(this, currentPassword, newPassword);
/*     */   }
/*     */   
/*     */   public void checkPasswordStrength(String password) throws ServiceException {
/*  79 */     getProvisioning().checkPasswordStrength(this, password);
/*     */   }
/*     */   
/*     */   public Provisioning.SetPasswordResult setPassword(String password) throws ServiceException {
/*  83 */     return getProvisioning().setPassword(this, password);
/*     */   }
/*     */   
/*     */   public Provisioning.GroupMembership getAclGroups(boolean adminGroupsOnly) throws ServiceException {
/*  87 */     return getProvisioning().getGroupMembership(this, adminGroupsOnly);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean inDistributionList(String zimbraId)
/*     */     throws ServiceException
/*     */   {
/*  96 */     return getProvisioning().inDistributionList(this, zimbraId);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public Set<String> getDistributionLists()
/*     */     throws ServiceException
/*     */   {
/* 104 */     return getProvisioning().getDistributionLists(this);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public List<DistributionList> getDistributionLists(boolean directOnly, Map<String, String> via)
/*     */     throws ServiceException
/*     */   {
/* 117 */     return getProvisioning().getDistributionLists(this, directOnly, via);
/*     */   }
/*     */   
/*     */   public void preAuthAccount(String accountName, String accountBy, long timestamp, long expires, String preAuth, Map<String, Object> authCtxt) throws ServiceException
/*     */   {
/* 122 */     getProvisioning().preAuthAccount(this, accountName, accountBy, timestamp, expires, preAuth, authCtxt);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public void preAuthAccount(String accountName, String accountBy, long timestamp, long expires, String preAuth, boolean admin, Map<String, Object> authCtxt)
/*     */     throws ServiceException
/*     */   {
/* 130 */     getProvisioning().preAuthAccount(this, accountName, accountBy, timestamp, expires, preAuth, admin, authCtxt);
/*     */   }
/*     */   
/*     */   public Cos getCOS() throws ServiceException
/*     */   {
/* 135 */     return getProvisioning().getCOS(this);
/*     */   }
/*     */   
/*     */   public DataSource createDataSource(DataSourceType type, String dataSourceName, Map<String, Object> attrs) throws ServiceException {
/* 139 */     return getProvisioning().createDataSource(this, type, dataSourceName, attrs);
/*     */   }
/*     */   
/*     */   public DataSource createDataSource(DataSourceType type, String dataSourceName, Map<String, Object> attrs, boolean passwdAlreadyEncrypted) throws ServiceException {
/* 143 */     return getProvisioning().createDataSource(this, type, dataSourceName, attrs, passwdAlreadyEncrypted);
/*     */   }
/*     */   
/*     */   public void modifyDataSource(String dataSourceId, Map<String, Object> attrs) throws ServiceException {
/* 147 */     getProvisioning().modifyDataSource(this, dataSourceId, attrs);
/*     */   }
/*     */   
/*     */   public void deleteDataSource(String dataSourceId) throws ServiceException {
/* 151 */     getProvisioning().deleteDataSource(this, dataSourceId);
/*     */   }
/*     */   
/*     */   public List<DataSource> getAllDataSources() throws ServiceException {
/* 155 */     return getProvisioning().getAllDataSources(this);
/*     */   }
/*     */   
/*     */   public DataSource get(Key.DataSourceBy keyType, String key) throws ServiceException {
/* 159 */     return getProvisioning().get(this, keyType, key);
/*     */   }
/*     */   
/*     */   public DataSource getDataSourceByName(String name) throws ServiceException {
/* 163 */     return get(Key.DataSourceBy.name, name);
/*     */   }
/*     */   
/*     */   public DataSource getDataSourceById(String id) throws ServiceException {
/* 167 */     return get(Key.DataSourceBy.id, id);
/*     */   }
/*     */   
/*     */   public Identity createIdentity(String identityName, Map<String, Object> attrs) throws ServiceException {
/* 171 */     return getProvisioning().createIdentity(this, identityName, attrs);
/*     */   }
/*     */   
/*     */   public void modifyIdentity(String identityName, Map<String, Object> attrs) throws ServiceException {
/* 175 */     getProvisioning().modifyIdentity(this, identityName, attrs);
/*     */   }
/*     */   
/*     */   public void deleteIdentity(String identityName) throws ServiceException {
/* 179 */     getProvisioning().deleteIdentity(this, identityName);
/*     */   }
/*     */   
/*     */   public List<Identity> getAllIdentities() throws ServiceException {
/* 183 */     return getProvisioning().getAllIdentities(this);
/*     */   }
/*     */   
/*     */   public Identity get(Key.IdentityBy keyType, String key) throws ServiceException {
/* 187 */     return getProvisioning().get(this, keyType, key);
/*     */   }
/*     */   
/*     */   public Identity getIdentityByName(String name) throws ServiceException {
/* 191 */     return get(Key.IdentityBy.name, name);
/*     */   }
/*     */   
/*     */   public Identity getIdentityById(String id) throws ServiceException {
/* 195 */     return get(Key.IdentityBy.id, id);
/*     */   }
/*     */   
/* 198 */   public Identity getDefaultIdentity() throws ServiceException { return getProvisioning().getDefaultIdentity(this); }
/*     */   
/*     */   public Signature createSignature(String signatureName, Map<String, Object> attrs) throws ServiceException
/*     */   {
/* 202 */     return getProvisioning().createSignature(this, signatureName, attrs);
/*     */   }
/*     */   
/*     */   public void modifySignature(String signatureId, Map<String, Object> attrs) throws ServiceException {
/* 206 */     getProvisioning().modifySignature(this, signatureId, attrs);
/*     */   }
/*     */   
/*     */   public void deleteSignature(String signatureId) throws ServiceException {
/* 210 */     getProvisioning().deleteSignature(this, signatureId);
/*     */   }
/*     */   
/*     */   public List<Signature> getAllSignatures() throws ServiceException {
/* 214 */     return getProvisioning().getAllSignatures(this);
/*     */   }
/*     */   
/*     */   public Signature get(Key.SignatureBy keyType, String key) throws ServiceException {
/* 218 */     return getProvisioning().get(this, keyType, key);
/*     */   }
/*     */   
/*     */   public Signature getSignatureByName(String key) throws ServiceException {
/* 222 */     return get(Key.SignatureBy.name, key);
/*     */   }
/*     */   
/*     */   public Signature getSignatureById(String key) throws ServiceException {
/* 226 */     return get(Key.SignatureBy.id, key);
/*     */   }
/*     */   
/*     */   public boolean isAccountStatusActive() {
/* 230 */     return "active".equals(getAccountStatus(getProvisioning()));
/*     */   }
/*     */   
/*     */   public boolean isAccountExternal() throws ServiceException {
/* 234 */     Server server = getServer();
/* 235 */     if (server == null) {
/* 236 */       return true;
/*     */     }
/* 238 */     return !server.mailTransportMatches(getAttr("zimbraMailTransport"));
/*     */   }
/*     */   
/*     */   public Server getServer() throws ServiceException {
/* 242 */     String serverName = getAttr("zimbraMailHost");
/* 243 */     return serverName == null ? null : getProvisioning().get(Key.ServerBy.name, serverName);
/*     */   }
/*     */   
/*     */   public String getServerName() throws ServiceException {
/* 247 */     Server server = getServer();
/*     */     
/*     */ 
/* 250 */     if (server != null) {
/* 251 */       return server.getName();
/*     */     }
/* 253 */     return null;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public String getAccountStatus(Provisioning prov)
/*     */   {
/* 260 */     String domainStatus = null;
/* 261 */     String accountStatus = getAttr("zimbraAccountStatus");
/*     */     
/* 263 */     boolean isAdmin = getBooleanAttr("zimbraIsAdminAccount", false);
/* 264 */     boolean isDomainAdmin = getBooleanAttr("zimbraIsDomainAdminAccount", false);
/* 265 */     isAdmin = (isAdmin) && (!isDomainAdmin);
/* 266 */     if (isAdmin) {
/* 267 */       return accountStatus;
/*     */     }
/*     */     
/* 270 */     if (this.mDomain != null) {
/*     */       try {
/* 272 */         Domain domain = prov.getDomain(this);
/* 273 */         if (domain != null) {
/* 274 */           domainStatus = domain.getDomainStatusAsString();
/*     */         }
/*     */       } catch (ServiceException e) {
/* 277 */         ZimbraLog.account.warn("unable to get domain for account " + getName(), e);
/* 278 */         return accountStatus;
/*     */       }
/*     */     }
/*     */     
/* 282 */     if ((domainStatus == null) || (domainStatus.equals("active")))
/* 283 */       return accountStatus;
/* 284 */     if (domainStatus.equals("locked")) {
/* 285 */       if ((accountStatus.equals("maintenance")) || (accountStatus.equals("pending")) || (accountStatus.equals("closed")))
/*     */       {
/*     */ 
/* 288 */         return accountStatus;
/*     */       }
/* 290 */       return "locked"; }
/* 291 */     if ((domainStatus.equals("maintenance")) || (domainStatus.equals("suspended")) || (domainStatus.equals("shutdown")))
/*     */     {
/*     */ 
/* 294 */       if ((accountStatus.equals("pending")) || (accountStatus.equals("closed")))
/*     */       {
/* 296 */         return accountStatus;
/*     */       }
/* 298 */       return "maintenance";
/*     */     }
/*     */     
/* 301 */     return "closed";
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public boolean isCalendarResource()
/*     */   {
/* 308 */     return getAttr("zimbraCalResType") != null;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean checkAuthTokenValidityValue(AuthToken at)
/*     */     throws ServiceException
/*     */   {
/* 320 */     if (!getProvisioning().getConfig().isAuthTokenValidityValueEnabled()) {
/* 321 */       return true;
/*     */     }
/* 323 */     int acctValue = getAuthTokenValidityValue();
/* 324 */     int authTokenValue = at.getValidityValue();
/*     */     
/* 326 */     if (acctValue == authTokenValue) {
/* 327 */       return true;
/*     */     }
/* 329 */     ZimbraLog.account.debug("checkAuthTokenValidityValue: validity value on account = " + acctValue + ", validity value on auth token = " + authTokenValue);
/*     */     
/*     */ 
/* 332 */     if (acctValue < authTokenValue)
/*     */     {
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 378 */       Integer highestReloadedFor = (Integer)getCachedData(EntryCacheDataKey.ACCOUNT_VALIDITY_VALUE_HIGHEST_RELOAD.getKeyName());
/* 379 */       boolean willReload = (highestReloadedFor == null) || (highestReloadedFor.intValue() < authTokenValue);
/*     */       
/* 381 */       ZimbraLog.account.debug("checkAuthTokenValidityValue: highest validity value reloaded for = " + highestReloadedFor + ", will reload = " + willReload);
/*     */       
/*     */ 
/* 384 */       if (willReload) {
/* 385 */         ZimbraLog.account.debug("checkAuthTokenValidityValue: reloading account " + getName() + " for validity value " + authTokenValue);
/* 386 */         getProvisioning().reload(this, false);
/* 387 */         setCachedData(EntryCacheDataKey.ACCOUNT_VALIDITY_VALUE_HIGHEST_RELOAD.getKeyName(), Integer.valueOf(authTokenValue));
/*     */         
/*     */ 
/*     */ 
/* 391 */         acctValue = getAuthTokenValidityValue();
/* 392 */         ZimbraLog.account.debug("checkAuthTokenValidityValue: validity value on account after reload = " + acctValue);
/* 393 */         return acctValue == authTokenValue;
/*     */       }
/*     */     }
/*     */     
/* 397 */     return false;
/*     */   }
/*     */   
/*     */   public void setAccountDefaults(boolean setSecondaryDefaults) throws ServiceException
/*     */   {
/* 402 */     Cos cos = getProvisioning().getCOS(this);
/*     */     
/* 404 */     Map<String, Object> defaults = null;
/* 405 */     if (cos != null) {
/* 406 */       defaults = cos.getAccountDefaults();
/*     */     }
/* 408 */     if (!setSecondaryDefaults)
/*     */     {
/* 410 */       setDefaults(defaults);
/*     */     }
/*     */     else {
/* 413 */       Map<String, Object> secondaryDefaults = null;
/* 414 */       Domain domain = getProvisioning().getDomain(this);
/* 415 */       if (domain != null)
/* 416 */         secondaryDefaults = domain.getAccountDefaults();
/* 417 */       setDefaults(defaults, secondaryDefaults);
/*     */     }
/*     */   }
/*     */   
/*     */   public String[] getAllAddrsAsGroupMember()
/*     */     throws ServiceException
/*     */   {
/* 424 */     if (isIsExternalVirtualAccount()) {
/* 425 */       return new String[] { getExternalUserMailAddress() };
/*     */     }
/* 427 */     String[] aliases = getMailAlias();
/* 428 */     List<String> addrs = Lists.newArrayListWithExpectedSize(aliases.length + 1);
/* 429 */     String myName = getName();
/* 430 */     addrs.add(myName);
/* 431 */     for (String alias : aliases) {
/* 432 */       if (!alias.equals(myName)) {
/* 433 */         addrs.add(alias);
/*     */       }
/*     */     }
/* 436 */     return (String[])addrs.toArray(new String[0]);
/*     */   }
/*     */   
/*     */ 
/*     */   public String[] getAliases()
/*     */     throws ServiceException
/*     */   {
/* 443 */     return getMailAlias();
/*     */   }
/*     */   
/*     */   public boolean isAddrOfEntry(String addr)
/*     */   {
/* 448 */     addr = addr.toLowerCase();
/* 449 */     if (getName().equals(addr)) {
/* 450 */       return true;
/*     */     }
/* 452 */     Set<String> aliases = getMultiAttrSet("zimbraMailAlias");
/* 453 */     return aliases.contains(addr);
/*     */   }
/*     */   
/*     */ 
/*     */   public Set<String> getAllAddrsSet()
/*     */   {
/* 459 */     Set<String> addrs = Sets.newHashSet();
/* 460 */     addrs.add(getName());
/* 461 */     addrs.addAll(getMultiAttrSet("zimbraMailAlias"));
/* 462 */     return Collections.unmodifiableSet(addrs);
/*     */   }
/*     */   
/*     */   public UCService getUCService() throws ServiceException {
/* 466 */     String ucServiceId = getAttr("zimbraUCServiceId");
/* 467 */     return ucServiceId == null ? null : getProvisioning().get(Key.UCServiceBy.id, ucServiceId);
/*     */   }
/*     */   
/*     */   public String getUCUsername()
/*     */   {
/* 472 */     String ucUsername = super.getUCUsername();
/* 473 */     if (ucUsername == null) {
/*     */       try {
/* 475 */         NameUtil.EmailAddress emailAddr = new NameUtil.EmailAddress(getName());
/* 476 */         ucUsername = emailAddr.getLocalPart();
/*     */       } catch (ServiceException e) {
/* 478 */         ZimbraLog.account.warn("ignoring exception while getting localpart of primary email address", e);
/*     */       }
/*     */     }
/* 481 */     return ucUsername;
/*     */   }
/*     */   
/*     */   public String getDecryptedUCPassword() throws ServiceException {
/* 485 */     String encryptedPassword = getUCPassword();
/* 486 */     if (encryptedPassword == null) {
/* 487 */       return null;
/*     */     }
/* 489 */     return DataSource.decryptData(getId(), encryptedPassword);
/*     */   }
/*     */   
/*     */   public void changeUCPassword(String newPlainPassword) throws ServiceException
/*     */   {
/* 494 */     String encryptedPassword = null;
/*     */     
/* 496 */     if (newPlainPassword != null) {
/* 497 */       encryptedPassword = encrypytUCPassword(getId(), newPlainPassword);
/*     */     }
/*     */     
/* 500 */     setUCPassword(encryptedPassword);
/*     */   }
/*     */   
/*     */   public static String encrypytUCPassword(String acctId, String plainPassword) throws ServiceException
/*     */   {
/* 505 */     return DataSource.encryptData(acctId, plainPassword);
/*     */   }
/*     */   
/*     */   public void cleanExpiredTokens() throws ServiceException {
/* 509 */     String[] tokens = getAuthTokens();
/* 510 */     for (String tk : tokens) {
/* 511 */       String[] tokenParts = tk.split("\\|");
/* 512 */       if (tokenParts.length > 0) {
/* 513 */         String szExpire = tokenParts[1];
/* 514 */         Long expires = Long.valueOf(Long.parseLong(szExpire));
/* 515 */         if (System.currentTimeMillis() > expires.longValue()) {
/* 516 */           removeAuthTokens(tk);
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/Account.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */